package com.chang.bootplus.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chang.bootplus.base.utils.ApiResponse;
import com.chang.bootplus.base.utils.BeanUtil;
import com.chang.bootplus.entity.StuTest;
import com.chang.bootplus.mapper.StuTestMapper;
import com.chang.bootplus.po.ResultPO;
import com.chang.bootplus.po.StudentResultPO;
import com.chang.bootplus.service.StuTestService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chang.bootplus.vo.ResultVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chang
 * @since 2022-02-02
 */
@Service
public class StuTestServiceImp extends ServiceImpl<StuTestMapper, StuTest> implements StuTestService {

    @Override
    public ApiResponse<ResultVO> getHistoryResult(ResultPO po) {
        Page page = new Page(po.getPageNumber(), po.getPageSize());
        //按时间升序
        Page pages = page(page, new LambdaQueryWrapper<StuTest>().eq(StuTest::getStuId, po.getStuId()).orderByAsc(StuTest::getGmtCreate));

        List<StuTest> list = BeanUtil.listA2ListB(pages.getRecords(), StuTest.class);


        LinkedList<ResultVO> resultVOS = new LinkedList<>();
        if (po.getProjectId()==1){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getVital()).setLocalDateTime(t.getGmtCreate()));
            });
        } else if (po.getProjectId()==2){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getTestFifty()).setLocalDateTime(t.getGmtCreate()));
            });
        }else if (po.getProjectId()==3){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getTestSitRech()).setLocalDateTime(t.getGmtCreate()));
            });
        }else if (po.getProjectId()==4){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getTestSkip()).setLocalDateTime(t.getGmtCreate()));
            });
        }else if (po.getProjectId()==5){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getTestSitup()).setLocalDateTime(t.getGmtCreate()));
            });
        }else if (po.getProjectId()==6){
            list.stream().forEach(t->{
                resultVOS.add(new ResultVO().setScore(t.getTestRun()).setLocalDateTime(t.getGmtCreate()));
            });
        }
        return new ApiResponse<>(resultVOS);
    }


}
